package org.walkerljl.practice;

import org.walkerljl.commons.io.FileUtils;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
 * TextWriter
 *
 * @author lijunlin
 */
public class TextWriter {

    public static void main(String[] args) throws IOException {
        StringBuilder sql = new StringBuilder();
        for (int index = 1; index <= 512; index++) {
            sql.append("create index index_pin on coupon_user_" + index + "(pin);\r\n");
            sql.append("create index index_batch_id on coupon_user_" + index + "(batch_id);\r\n");
        }
        writeFile("C:/Users/俊林/Desktop/EPT优惠券数据库索引脚本", "ept_coupon_4索引脚本.sql", sql.toString());
    }

    public static void writeFile(String path, String fileName, String content) {
        BufferedWriter writer = null;
        try {
            FileUtils.mkdirs(path);
            writer = new BufferedWriter(new FileWriter(path + "/" + fileName));
            writer.write(content);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (Exception e2) {
                    //LOG.error("关闭输出对象出错");
                }
            }
        }
    }
}